package com.yinhe.music.yhmusic.manager;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.dou361.dialogui.DialogUIUtils;
import com.dou361.dialogui.bean.BuildBean;
import com.dou361.dialogui.listener.DialogUIListener;
import com.yinhe.music.yhmusic.base.BaseActivity;
import com.yinhe.music.yhmusic.model.Music;
import com.yinhe.music.yhmusic.utils.Preferences;

/**
 * @author 何晓华
 * @date 2018/1/3
 */

public class DialogActivity extends BaseActivity {
    private Music music;
    public static final int FIRST_PLAY = 0, RESUME_PLAY = 1;
    private int type;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getIntent() != null) {
            music = (Music) getIntent().getSerializableExtra("music");
            type = getIntent().getIntExtra("type", 0);
        }

        DialogUIListener listener = new DialogUIListener() {
            @Override
            public void onPositive() {
                Preferences.setIsProtect(false);
                mService.playMusic(music);
                finish();
            }

            @Override
            public void onNegative() {
                finish();
            }
        };

        DialogUIListener changeListener = new DialogUIListener() {
            @Override
            public void onPositive() {
                mService.resume();
                finish();
            }

            @Override
            public void onNegative() {
                mService.pause();
                finish();
            }
        };

        if (type == FIRST_PLAY) {
            showProtectDialog(listener);
        } else if (type == RESUME_PLAY) {
            showProtectDialog(changeListener);
        }

    }

    private void showProtectDialog(DialogUIListener listener) {
        final BuildBean dialog = DialogUIUtils.showAlert(this, "提示",
                "当前网络无WIFI，继续在线听可能被运营商收取流量费用", null,
                null, "继续播放", "暂不播放", false,
                false, false, listener);
        dialog.show();
    }

}
